package com.hopes.bizz.risk.statistic.serivce.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopes.bizz.risk.control.service.RiskMeasureTaskService;
import com.hopes.bizz.risk.control.vo.RiskObjectVO;
import com.hopes.bizz.risk.statistic.dto.SafetyStatisticsDTO;
import com.hopes.bizz.risk.statistic.serivce.SafetyStatisticsService;
import com.hopes.bizz.risk.statistic.vo.SafetyStatisticsExcelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/8/1 17:52
 * @Description:
 */
@Service
public class SafetyStatisticsServiceImpl implements SafetyStatisticsService {

    @Autowired
    private RiskMeasureTaskService riskMeasureTaskService;

    @Override
    public List<SafetyStatisticsExcelVO> exportExcel(SafetyStatisticsDTO dto) {
        Page<RiskObjectVO> riskObjectVOPage = riskMeasureTaskService.taskStatistics(new Page(), dto);
        List<SafetyStatisticsExcelVO> voList = new ArrayList<>();
        for (RiskObjectVO record : riskObjectVOPage.getRecords()) {
            SafetyStatisticsExcelVO vo = new SafetyStatisticsExcelVO();
            vo.setHazardName(record.getHazardName());

            JSONObject safetyStatistics = record.getSafetyStatistics();
            vo.setTotalFinish(safetyStatistics.getJSONObject("total").getString("finish"));
            vo.setTotalPercent(safetyStatistics.getJSONObject("total").getString("percent") +"%");

            vo.setMainTaskFinish(safetyStatistics.getJSONObject("mainTask").getString("finish"));
            vo.setMainTaskPercent(safetyStatistics.getJSONObject("mainTask").getString("percent") +"%");

            vo.setTechnologyTaskFinish(safetyStatistics.getJSONObject("technologyTask").getString("finish"));
            vo.setTechnologyTaskPercent(safetyStatistics.getJSONObject("technologyTask").getString("percent") +"%");

            vo.setOperationTaskFinish(safetyStatistics.getJSONObject("operationTask").getString("finish"));
            vo.setOperationTaskPercent(safetyStatistics.getJSONObject("operationTask").getString("percent") +"%");

            vo.setHidTotal(safetyStatistics.getJSONObject("hid").getString("finish"));
            vo.setHidFinish(safetyStatistics.getJSONObject("hid").getString("percent") +"%");


            voList.add(vo);
        }
        return voList;
    }
}
